<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        li {
            list-style: none;
        }

        .bd {
            width: 500px;
            margin: 200px auto;
        }

        .comment .in {
            width: 200px;
            height: 200px;
        }

        .comment .btn {
            width: 40px;
            height: 25px;
        }

        .disply li {
            background-color: #ccc;
            margin-top: 5px;
        }

        .dele {
            float: right;
            color: blueviolet;
        }
    </style>
</head>

<body>
    <div class="bd">
        <div class="comment">
            <input type="text" name="" id="" class="in">
            <input type="button" value="" class="btn">
        </div>
        <ul class="disply">
            <li>comment1</li>
        </ul>
    </div>

</body>

<script>
    var input = document.querySelector('.in');
    var btn = document.querySelector('.btn');
    var disply = document.querySelector('.disply');
    btn.onclick = function () {
        if (input.value != '') {
            var li = document.createElement('li');
            li.innerHTML = input.value + '<span href="" class=\'dele\'>删除</span>';
            input.value = '';
            disply.appendChild(li);

        }
        else {
            alert('Please input sth!')
        }
        dele = document.querySelectorAll('.dele');
        for (var i = 0; i < dele.length; i++) {
            dele[i].onclick = function () {
                console.log(i);
                this.parentElement.parentElement.removeChild(this.parentElement);
            }
        }

    }


</script>

</html>